﻿using JQData.Core.DbModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JQData.Core.DataModel
{
    ///游资买入卖出的数量都按照当日平均价计算




    /// <summary>
    /// 游资数据
    /// </summary>
    public class HotMoneyData
    {
        public int HotMoneyId { get; set; }

        public HotMoney DbHotMoney { get; set; }

        public string HotMoneyName { get; set; }



        public List<HotMoneyDataChart> TopChart { get; set; } = new();

        public List<HotMoneyStockData> Day7 { get; set; } = new();

        public List<HotMoneyStockData> Day30 { get; set; } = new();


        /// <summary>
        /// 每天的数据统计 ，最近30天的游资数据
        /// </summary>
        public List<HotMoneyDataDayStats> DayStats { get; set; } = new();

    }


    /// <summary>
    /// 游资持股
    /// </summary>
    public class HotMoneyStockData
    {
        public int StockId { get; set; }

        public StockBasic DbStock { get; set; }

        public string StockName { get; set; }


        /// <summary>
        /// !!!当前价格，现在用的是最后一天的收盘价，会有延迟
        /// </summary>
        public decimal CurrentPrice { get; set; }


        /// <summary>
        /// !!!买入时间,现在是第一个买单的时间，有可能更早  
        /// </summary>
        public DateOnly BuyDate { get; set; }



        /// <summary>
        /// 成本价格
        /// </summary>
        public decimal CostPrice { get; set; }

        /// <summary>
        /// 剩余仓位
        /// </summary>
        public decimal RemainingPosition { get; set; }


        /// <summary>
        /// !!!持仓比例,这只股票在游资总持仓中的比例
        /// </summary>
        public float PositionRatio { get; set; }

        /// <summary>
        /// 买入信息
        /// </summary>
        public List<HotMoneyStockDataTradeItem> BuyInfo { get; set; }

        /// <summary>
        /// 卖出信息
        /// </summary>
        public List<HotMoneyStockDataTradeItem> SellInfo { get; set; }


        /// <summary>
        /// 图表数据
        /// </summary>
        public List<HotMoneyStockDataChartItem> Chart { get; set; }

        /// <summary>
        /// 每天的数据统计
        /// </summary>
        public List<HotMoneyStockDataDayStats> StockDayStats { get; set; }




        /// <summary>
        /// 买入金额
        /// </summary>
        public decimal BuyAmount => BuyInfo.Sum(i => i.Amount);
        /// <summary>
        /// 卖出金额
        /// </summary>
        public decimal SellAmount => SellInfo.Sum(i => i.Amount);

        /// <summary>
        /// 净买入金额
        /// </summary>
        public decimal NetBuyAmount => BuyAmount - SellAmount;

        /// <summary>
        /// 是否浮盈
        /// </summary>
        public bool IsWin => CostPrice <= CurrentPrice;

        /// <summary>
        /// 浮盈百分比，亏损为负数，盈利为正数
        /// </summary>
        public decimal WinPercent => CostPrice == 0 ? 0 : Math.Round((CurrentPrice - CostPrice) / CostPrice * 100, 2);

       

    }


    /// <summary>
    /// 游资每天的数据统计
    /// </summary>
    public class HotMoneyDataDayStats
    {

        /// <summary>
        /// 日期
        /// </summary>
        public DateOnly Date { get; set; }

        /// <summary>
        /// 当天买入 总额
        /// </summary>
        public decimal BuyAmount { get; set; }

        /// <summary>
        /// 当天卖出 总额
        /// </summary>

        public decimal SellAmount { get; set; }


        /// <summary>
        /// 每天的 净买入总额
        /// </summary>
        public decimal NetAmount => BuyAmount - SellAmount;

    }


    /// <summary>
    /// 统计每天的数据
    /// </summary>
    public class HotMoneyStockDataDayStats
    {


        public DateOnly Date { get; set; }

        public decimal WinPercent => CostPrice == 0 ? 0 : Math.Round((CurrentPrice - CostPrice) / CostPrice * 100, 2);

        public decimal WinPrice => CostPrice == 0 ? 0 : (CurrentPrice - CostPrice) * RemainingPosition;

        public bool IsWin => CostPrice <= CurrentPrice;

        /// <summary>
        /// 当天买入 总额
        /// </summary>
        public decimal BuyAmount { get; set; }

        /// <summary>
        /// 当天卖出 总额
        /// </summary>

        public decimal SellAmount { get; set; }


        /// <summary>
        /// 当天股票价格，目前是收盘价
        /// </summary>
        public decimal CurrentPrice { get; set; }

        /// <summary>
        /// 截至到当天的成本价，目前是收盘价
        /// </summary>
        public decimal CostPrice { get; set; }

        /// <summary>
        /// 剩余仓位，单位1000股
        /// </summary>
        public decimal RemainingPosition { get; set; }
    }



    public class HotMoneyDataChart
    {
        public string Title { get; set; }

        public string Value { get; set; }

        public string Chang { get; set; }

        public bool IsUp { get; set; }

        public List<decimal> Data { get; set; } = new List<decimal>();

        public List<decimal> Data2 { get; set; } = new List<decimal>();

        public List<decimal> Data3 { get; set; } = new List<decimal>();

        public List<string> Date { get; set; } = new List<string>();

        public string Type { get; set; }

    }


    public class HotMoneyStockDataTradeItem
    {
        /// <summary>
        /// 总金额
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 手数
        /// </summary>
        public decimal Vol { get; set; }

        /// <summary>
        /// 均价
        /// </summary>
        public decimal Price { get; set; }

        /// <summary>
        /// 交易日期
        /// </summary>
        public DateOnly Date { get; set; }
    }


    /// <summary>
    /// 游资持仓情况表格内的图表数据
    /// </summary>
    public class HotMoneyStockDataChartItem
    {
        public string Date { get; set; }
        public decimal BuyVol { get; set; }

        public decimal SellVol { get; set; }
        public decimal Price { get; set; }
    }

}
